<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    //await 一定要等到promise状态确定了才会往下执行

    /*new Promise((resolve, reject)=>{
        setTimeout(function (flag) {
            if(flag){
                console.log("第一次請求成功");
                resolve()
            }else{
                reject()
            }
        },1000,true)
    }).then(()=>{
        return new Promise((resolve, reject)=>{
            setTimeout(function (flag) {
                if(flag){
                    console.log("第二次請求成功");
                    resolve()
                }else{
                    reject()
                }
            },1000,true)
        })
    }).then(()=>{
        return new Promise((resolve, reject)=>{
            setTimeout(function (flag) {
                if(flag){
                    console.log("第三次請求成功");
                    resolve()
                }else{
                    reject()
                }
            },1000,true)
        })
    }).then(()=>{
        console.log("----")
    })*/


    //语法糖
    async function f() {
        await new Promise((resolve, reject)=>{
            setTimeout(function (flag) {
                if(flag){
                    console.log("第一次請求成功");
                    resolve()
                }else{
                    reject()
                }
            },1000,true)
        })
        await new Promise((resolve, reject)=>{
            setTimeout(function (flag) {
                if(flag){
                    console.log("第二次請求成功");
                    resolve()
                }else{
                    reject()
                }
            },1000,true)
        })
        await new Promise((resolve, reject)=>{
            setTimeout(function (flag) {
                if(flag){
                    console.log("第三次請求成功");
                    resolve()
                }else{
                    reject()
                }
            },1000,true)
        })
        console.log("----")
    }
    f()




</script>
</html>